<#include "/layout/layout.ftl">
<#import "/layout/macro.ftl" as macro>
<#import "/layout/select.ftl" as my/>
<#assign css>
<#--此ftl中用到的css-->
</#assign>
<#assign js>
<#--此ftl中用到的js-->
<script>
	$(".btn-submit").click(function () {
		// 校验表单合法
		//跑腿分类暂不允许添加子类别
		if($("#serviceClass").val()=='1'){
		    layer.alert("跑腿类别下暂不支持添加二级分类，请选择其他");
		    return ;

		}
        /*var isAdd = $("#isAdd").val();
		if(isAdd=="false"){
            $("#updateAll").value="0"
            layer.confirm('是否更新所有分站该分类定价方式、价格以及描述信息?', {icon: 3, btn: ['全部更新','仅更新系统默认'],title: '提示'}, function (index) {
                $("#updateAll").value="1"
                update(updateAll);
            },function(){
                update(updateAll);

            });

		}else{
            $("#updateAll").value="0"
            update("0");
		}*/
        update("0");


	});

	function update(updateAll){
		var isAdd = $("#isAdd").val();
        var bootstrapValidator = $(".form-edit").data('bootstrapValidator');
        bootstrapValidator.validate();
        if(bootstrapValidator.isValid()){
            $.ajax({
                type: "POST",
                url: "/agentService/edit",
                data: $(".form-edit").serialize(),
                dataType: "JSON",
                success: function(res){
                    layer.msg(res.message, {time: 2000
                    }, function(){
                        location.href="/agentService/index/${type}";
                    });
                }
            });
        }else{
            return false;
        }

	}

	$(function(){

	});

    $("#serviceClass").change(function (e){
        var serviceClass = e.currentTarget.value;

        $.ajax({
            type: "GET",
            url: "/agentService/getChildType/"+serviceClass,
            dataType: "JSON",
            success: function(res){
				debugger;
                $("#serviceCode option").remove();
                $("#serviceCode").append("<option value=''>请选择</option>");
                for(var key in res.data){
                    $("#serviceCode").append("<option value='"+key+"'>"+res.data[key]+"</option>");
                }

            }
        });
    });

    function tips(){
        var masterRate = $("#agentRate").val();//师傅提成比例
		var agentRate  = (100 - ${platRate} - masterRate).toFixed(2);;
        layer.tips('平台提成比例：${platRate}%<br/>' +
				'分站提成比例：'+agentRate+'%<br/>' +
				'师傅提成比例：'+masterRate+'%', '#tipsButton', {
            tips: [1, '#3595CC'],
            time: 5000
        });
	}


	$('.form-edit').bootstrapValidator({
		message: '请输入有效值',
		feedbackIcons: {
			valid: 'glyphicon glyphicon-ok',
			invalid: 'glyphicon glyphicon-remove',
			validating: 'glyphicon glyphicon-refresh'
		},
        fields: {
		    agentRate:{
                validators: {
                    notEmpty: {message: '分站抽成比例不能为空'},
                    numeric: {message: '分站抽成比例只能输入数字'}

                }
			}
        }
	});

</script>
</#assign>
<@layout title="编辑" active="oneclass">
<!-- Content Header (Page header) -->
<section class="content-header">
	<h1>
		<#if isAdd>
            新增
        <#else>
            编辑
        </#if>
		<small>二级分类详细信息</small>
	</h1>
	<ol class="breadcrumb">
		<li><a href="/"><i class="fa fa-home"></i> 管理后台</a></li>
		<li><a href="/agentService/index"><i class="fa fa-list-ul"></i> 上门服务二级分类管理</a></li>
		<li class="active"><i class="fa fa-edit"></i>
		    <#if isAdd>
                新增
            <#else>
                编辑
            </#if>
		</li>
	</ol>
</section>
<!-- Main content -->
<section class="content">
	<div class="row">
		<div class="col-md-12">
			<!-- Default box -->
			<div class="box  box-primary">
				<form class="form-horizontal form-edit" method="post" action="agentService/edit">
					<div class="box-body">
						<input type="hidden" id="id" name="id" value="${agentService.id!}">
						<input type="hidden" id="isAdd" name="isAdd" value="${isAdd?string('true','false')}">
						<input type="hidden" id="updateAll" name="updateAll">
						<#--<input type="hidden" id="serviceCode" name="serviceCode" value="${agentService.serviceCode!}">-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">一级分类：</label>
                            <div class="col-sm-10">
								<#if isAdd>
                                    <select id="serviceClass1"  class="form-control" required disabled>
                                        <option value="${oneClass.serviceClass}">${oneClass.serviceName}</option>
                                    </select>
                                    <input type="hidden" name="serviceClass" value="${oneClass.serviceClass!}">
								<#else >
									<@my.select id="serviceClass" datas=getDict('SERVICE_CLASS') disabled="true" value="${agentService.serviceClass!}" />
									<input type="hidden" name="serviceClass" value="${agentService.serviceClass!}">

								</#if>

                            </div>
                        </div>
						<div class="form-group">
							<label class="col-sm-2 control-label">二级分类名称：</label>
							<div class="col-sm-10">

								<#if isAdd>
                                    <select id="serviceCode" name="serviceCode" class="form-control" required>
                                        <option value="">请选择</option>
										<#list twoClassList as twoClass>
											<option value="${twoClass.serviceCode}">${twoClass.serviceName}</option>

										</#list>
                                    </select>
								<#else >
									<@my.select id="serviceCode" disabled="true" datas=getDict('SERVICE_CLASS_${agentService.serviceClass!}')  value="${agentService.serviceCode!}" />
									<input type="hidden" name="serviceCode" value="${agentService.serviceCode!}">
								</#if>
							</div>
						</div>

						<div class="form-group">
							<label class="col-sm-2 control-label">定价方式：</label>
							<div class="col-sm-10">
							    <@my.select id="priceWay" datas=getDict('PRICE_TYPE')  value="${agentService.priceWay!}" defaultValue="请选择" required="true"/>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label">定价/上门费：</label>
							<div class="col-sm-10">
								<input required placeholder="定价请输入定价费用/不定价请输入上门费用" id="fee" name="fee" class="form-control" type="text" value="${(agentService.fee?string.number)!}" >
							</div>
						</div>
						<div class="form-group">
                            <label class="col-sm-2 control-label">描述：</label>
                            <div class="col-sm-10">
                                <textarea  placeholder="请输入描述" id="serviceDesc" name="serviceDesc" class="form-control" required >${agentService.serviceDesc!}</textarea>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">师傅抽成比例(%)：</label>
                            <div class="col-sm-10">
                                <div class="input-group">
                                    <#--<input type="text" class="form-control" aria-label="...">-->
                                    <input  placeholder="请输入师傅抽成比例"  id="agentRate" name="agentRate" class="form-control" required type="numeric" value="${(agentService.agentRate?string.number)!}" min="0" max="${maxRate}">
                                    <div class="input-group-btn">
                                        <!-- Buttons -->
                                        <button type="button" id="tipsButton" onclick="tips()" class="btn btn-default" alt="sdfsdf">
                                            <span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span>
                                        </button>
                                    </div>
                                </div>

                            </div>
                        </div>


					<div class="box-footer">
						<button type="button" class="btn btn-default btn-back">返回</button>
						<button type="button" class="btn btn-info pull-right btn-submit">提交</button>
					</div>

				</form>
			</div>
			<!-- /.box -->
		</div>
	</div>
</section>
<!-- /.content -->
</@layout>
